package it.polimi.digitalstate.webbeans;

import it.polimi.digitalstate.dto.CitizenDTO;
import it.polimi.digitalstate.dto.UserDTO;
import it.polimi.digitalstate.manager.AuthenticationManagerLocal;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ViewScoped;

@ManagedBean(name="userBean")
@ViewScoped
public class UserBean {
	@EJB
	private AuthenticationManagerLocal ejb;
	private UserDTO user=null;
	private CitizenDTO citizen;
	//TODO distinguish then from citizen and governor :/
	
	@PostConstruct
	private void init() {
			user=ejb.getLoggedUser();
			if(ejb.aCitizenIsLogged()){
				citizen=ejb.getLoggedCitizen();
			}

	}
	public String getUsername(){
		return user.getUsername();
	}
	public String getName(){
		return citizen.getName();
	}
	public String getSurname(){
		return citizen.getSurname();
	}
	public boolean aCitizenIsLogged(){
		return ejb.aCitizenIsLogged();
	}
	public String getFullName(){
		return citizen.getName() + " " + citizen.getSurname();
	}
	public boolean isLogged(){
		return user!=null;
	}
}
